//
//  FirstView.m
//  UI16_DouBan
//
//  Created by dllo on 15/11/1.
//  Copyright © 2015年 张磊. All rights reserved.
//

#import "FirstView.h"

@implementation FirstView

- (void)dealloc
{
    [_nameLabel release];
    [_nameTextFild release];
    [_passwordLabel release];
    [_passwordTextFild release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

- (void)createSubView
{
    self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(30, 120, 100, 30)];
    [self addSubview:self.nameLabel];
    self.nameLabel.text = @"用户名:";
    [_nameLabel release];
    
    self.nameTextFild = [[UITextField alloc]initWithFrame:CGRectMake(self.nameLabel.frame.origin.x + 120, self.nameLabel.frame.origin.y, 200, 30)];
    [self addSubview:self.nameTextFild];
    self.nameTextFild.placeholder = @"请输入用户名";
    self.nameTextFild.borderStyle = UITextBorderStyleRoundedRect;
    
    
    self.passwordLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.nameLabel.frame.origin.x, self.nameLabel.frame.origin.y + 50, self.nameLabel.frame.size.width, self.nameLabel.frame.size.height)];
    [self addSubview:self.passwordLabel];
    self.passwordLabel.text = @"密码:";
    [_passwordLabel release];
    
    self.passwordTextFild = [[UITextField alloc]initWithFrame:CGRectMake(self.nameTextFild.frame.origin.x, self.passwordLabel.frame.origin.y, self.nameTextFild.frame.size.width, self.nameTextFild.frame.size.height)];
    [self addSubview:self.passwordTextFild];
    self.passwordTextFild.placeholder = @"请输入密码";
    self.passwordTextFild.borderStyle = UITextBorderStyleRoundedRect;
    [_passwordLabel release];
    
    
    self.btn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.btn.frame = CGRectMake(50, self.passwordLabel.frame.origin.y + 70, 120, 50);
    self.btn.backgroundColor = [UIColor greenColor];
    [self.btn setTitle:@"登陆" forState:UIControlStateNormal];
    [self.btn addTarget:self action:@selector(btn1:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.btn];
    
    self.btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    self.btn2.frame = CGRectMake(205, self.passwordLabel.frame.origin.y + 70, 120, 50);
    self.btn2.backgroundColor = [UIColor orangeColor];
    [self.btn2 setTitle:@"注册" forState:UIControlStateNormal];
    [self.btn2 addTarget:self action:@selector(btn2:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.btn2];
    
    
}

- (void)btn1:(UIButton *)btn
{
    [self.firstVDelegate setButtonToFirstVC];
}

- (void)btn2:(UIButton *)btn
{
    [self.secondVDelegate setButtonToSecondVC];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.nameTextFild resignFirstResponder];
    [self.passwordTextFild resignFirstResponder];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
